<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="">
          <el-input placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" icon="el-icon-search">搜索</el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-button type="primary" icon="el-icon-plus">添加</el-button>
        <el-button type="primary" icon="el-icon-refresh" @click="handleRefresh"
          >刷新</el-button
        >
      </div>
    </el-card>
    <el-card>
      <el-table :data="tbData" style="width: 100%">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column property="index" label="序号" width="60px">
          <template slot-scope="abc">
            {{ abc.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column property="categoryName" label="品类名称">
          <!-- <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.date }}</span>
      </template> -->
        </el-table-column>
        <el-table-column property="isActived" label="是否启用">
          <template slot-scope="scope">
            <span>{{ scope.row.isActived ? "启用" : "禁用" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新时间" property="updatedTime">
        </el-table-column>
        <el-table-column label="备注" property="remarks">
          <div class="slh" slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>住址: {{ scope.row.remarks }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="mini">{{ scope.row.remarks }}</el-tag>
              </div>
            </el-popover>
          </div>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      tbData: [],
      tableData: [
        {
          index: 1,
          categoryName: "手机",
          isActived: true,
          updatedTime: "2011.12.15 14:54:03",
          remarks: "没有备注",
        },
        {
          index: 2,
          categoryName: "老人机",
          isActived: false,
          updatedTime: "2011.12.15 14:54:03",
          remarks: "没有备注",
        },
        {
          index: 3,
          categoryName: "战斗机",
          isActived: true,
          updatedTime: "2011.12.15 14:54:03",
          remarks: "没有备注",
        },
        {
          index: 4,
          categoryName: "智能机",
          isActived: true,
          updatedTime: "2011.12.15 14:54:03",
          remarks: "没有备注",
        },
      ],
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    getData() {
      axios.get("/article/category").then(({ data }) => {
        console.log(data);
        this.tbData = data.data;
      });
    },
    handleRefresh() {
      this.getData();
    },
  },
  created: function () {
    this.getData();
  },
};
</script>
<style>
.el-card__body {
  display: flex;
  justify-content: space-between;
}
.slh {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>